#pragma once

#include <Windows.h>
#include <WinInet.h>
#include <string>



namespace Gw2API{

#ifndef GW2API_C_STRUCTS
#define APP_ID "GW2API"
#define API_SERVER "api.guildwars2.com"
#define DYNAMIC_EVENTS_API "/v1/events.json?world_id="
#define WORLD_MAPPING_API "/v1/world_names.json?"
#define MAP_MAPPING_API "/v1/map_names.json?"
#define EVENT_MAPPING_API "/v1/event_names.json?"
#define WVW_MATCHES "/v1/wvw/matches.json"
#define WVW_MATCH_DETAILS "/v1/wvw/match_details.json?match_id="
#define WVW_OBJECTIVE_NAMES "/v1/wvw/objective_names.json?"
#define ITEMS_API "/v1/items.json?"
#define ITEM_DETAILS "/v1/item_details.json?item_id="
#define RECIPES_API "/v1/recipes.json?"
#define RECIPE_DETAILS "/v1/recipe_details.json?recipe_id="
#define GUILD_API "/v1/guild_details.json?"
#define API_BUILD "/v1/build.json?"
#define COLORS_API "/v1/colors.json?"
#define GW2API_LANG_DE 0
#define GW2API_LANG_FR 1
#define GW2API_LANG_EN 2
#endif

class WebConnection
{
public:
	WebConnection(void);
	~WebConnection(void);

	//sends a worldmapping request to the server, returns the recieved answer as a string
	std::string WorldMappingRequest();

	//sends a mapmapping request to the server, returns the recieved answer as a string
	std::string MapMappingRequest();

	//sends an eventmapping request to the server, returns the recieved answer as a string
	std::string EventdMappingRequest();

	//sends an eventstate request to the server, returns the recieved answer as a string @param: strPtr world_id, map_id, event_id
	std::string EventStateRequest(std::string *world_id, std::string *map_id, std::string *event_id);

	//requests the current matchmapping from the server
	std::string MatchMappingRequest();

	//requests a match's details from the server @param: strPtr match_id
	std::string MatchDetailsRequest(std::string *match_id);

	//requests the objective names from the server
	std::string WVWObjectiveNamesRequest();

	//requests a list of all discovered Items
	std::string ItemListRequest();

	//requests an item's details
	std::string ItemDetailsRequest(std::string *id);

	//requests a list of all discovered Recipes
	std::string RecipeListRequest();

	//requests an recipe's details
	std::string RecipeDetailsRequest(std::string *id);

	//guild request
	std::string GuildAPIRequest(std::string *id, std::string *name);

	//requests the current build
	std::string ApiBuildRequest();

	//requests a list of colors
	std::string ColorRequest();

	//sets the current language defined in the GW2API_LANG_* macros, on default set to 0, returns true on success
	bool setLanguage(int lang);

private:
	void startSession();
	void endSession();
	LPCWSTR convertToWideChar(std::string);
	std::string recieveServerResponse(HINTERNET requestHandle);
	std::string sendServerRequest(std::string *request);

	HINTERNET openHandle, sessionHandle;
	int lang;
	std::string languages[3];
};

};